package com.fenghongzhang.zhoukao2;

import androidx.appcompat.app.AppCompatActivity;

import android.content.SharedPreferences;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;

public class Main4Activity extends AppCompatActivity  {
    private EditText edit;
    private Button btn;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main4);



        edit = (EditText) findViewById(R.id.edit);
        btn = (Button) findViewById(R.id.btn);


        SharedPreferences login = getSharedPreferences("login", MODE_PRIVATE);
        long time = login.getLong("time", System.currentTimeMillis());
        final long l = System.currentTimeMillis();
        if(l - time / 1000 / 60 > 5){
            //登录时间过了5分钟中了.跳转
//            vp.setC(1);
        }else{
            //取值
            String name = login.getString("name", "");
            edit.setText(name);
            login.getString("pwd","");
        }


        btn.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                SharedPreferences login = getSharedPreferences("login", MODE_PRIVATE);
                SharedPreferences.Editor edit = login.edit();
                edit.putFloat("time",System.currentTimeMillis()); // 02.
                edit.putString("name","name");
                edit.putString("pwd","pwd");
                edit.commit();
            }
        });
    }
}
